package com.feifan.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.feifan.api.dto.UmsAdminLoginParam;
import com.feifan.api.model.UmsAdmin;
import com.feifan.api.service.IUserService;
import com.feifan.provider.mapper.UmsAdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: FinalProject
 * @author: Xiaofan
 * @createTime: 2021-08-03 09:48
 * @description: Functions of this class is
 **/
@Transactional//用于管理事务
@Service(version = "1.0.0",
         interfaceName = "com.feifan.api.service.IUserService",
         interfaceClass = IUserService.class)
public class UserService implements IUserService {

    @Autowired
    private UmsAdminMapper dao;

    @Autowired
    private TokenService tokenService;
    @Override
    public UmsAdmin findByUsername(String username) {
        return dao.findByUsername(username);
    }

    @Override
    public UmsAdmin Login(UmsAdminLoginParam user) {
        return null;
    }

    @Override
    public UmsAdmin findByToken(String token) {
        String userId=tokenService.getUserId(token);
        return findByUserId(userId);
    }

    @Override
    public UmsAdmin findByUserId(String userId) {
        return dao.selectByPrimaryKey(Long.parseLong(userId));
    }

    @Override
    public UmsAdmin register(UmsAdmin user) {
        String icon="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2Fa6915b9d49166dd6d2763679c3ba631c8d42e5b2.jpg&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1630652816&t=f1c1bb69ca1f9c2cf991e4e939ffe266";
        user.setIcon(icon);
        dao.insert(user);
        return user;
    }
}